<template>
  <div>
    <van-cell border>
      <!-- 使用 title 插槽来自定义标题 -->
      <template #title>
        <div class="title-box">
          <span>{{ articleItem.title }}</span>
          <!-- <img
            class="thumb"
            :src="articleItem.cover.images[0]"
            alt=""
            v-if="articleItem.cover.type === 1"
          /> -->
          <van-image
            class="thumb"
            v-if="articleItem.cover.type === 1"
            :src="articleItem.cover.images[0]"
          >
            <template v-slot:error>图片学习呢</template>
          </van-image>
        </div>
        <div class="thumb-box" v-if="articleItem.cover.type > 1">
          <!-- <img
            v-for="(item, index) in articleItem.cover.images"
            :key="index"
            class="thumb"
            :src="item"
            alt=""
          /> -->
          <van-image
            v-for="(item, index) in articleItem.cover.images"
            :key="index"
            class="thumb"
            :src="item"
          >
            <template v-slot:error>图片学习呢</template>
          </van-image>
        </div>
      </template>
      <template #label>
        <div class="label-box">
          <div>
            <span>{{ articleItem.art_name }}</span>
            <span>{{ articleItem.comm_count }}评论</span>
            <span>{{ formatTime(articleItem.pubdate) }}</span>
          </div>
          <van-icon name="cross" @click.stop="show = true" v-if="isShow" />
        </div>
      </template>
    </van-cell>
    <van-action-sheet
      v-model="show"
      :cancel-text="txt"
      @cancel="goBack"
      :actions="actions"
      @select="onSelect"
      @close="onClose"
      get-container="body"
    />
  </div>
</template>

<script>
import { timeAgo } from "@/utils/date";
import { firstActions, secondActions } from "@/api/report";
export default {
  props: {
    articleItem: Object,
    isShow: {
      type: Boolean,
      default: true,
    },
  },
  name: "articleItem",
  data() {
    return {
      formatTime: timeAgo,
      show: false,
      actions: firstActions,
      txt: "取消",
    };
  },
  methods: {
    onSelect(action) {
      if (action.name == "反馈垃圾内容") {
        this.actions = secondActions;
        this.txt = "返回";
      } else if (action.name == "不感兴趣") {
        this.$emit("diseLikeArticle", this.articleItem.art_id);
        this.show = false;
      } else {
        this.$emit("reportArticle", this.articleItem.art_id, action.value);
        this.show = false;
      }
    },
    goBack() {
      if (this.txt == "返回") {
        this.show = true;
        this.actions = firstActions;
        this.txt = "取消";
      }
    },
    onClose() {
      this.actions = firstActions;
      this.txt = "取消";
    },
    // cellClick(){
    //    console.log(1);
    // 因为当前组件可能被其他页面使用
    // }
  },
};
</script>

<style lang="less" scoped>
.label-box {
  display: flex;
  justify-content: space-between;
  span {
    margin: 0 6px;
    margin-left: 0;
  }
}
.van-cell__title {
  border-bottom: 1px solid #eee;
  padding-bottom: 6px;
}
.title-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.thumb {
  width: 113px;
  height: 70px;
  background-color: #f8f8f8;
  object-fit: cover;
}
.thumb-box {
  display: flex;
  justify-content: space-between;
}
</style>